﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace vukhoas.src.POJO
{
	public class Product
	{
        private string categoryName;

        public string CategoryName
        {
            get { return getCategoryName(); }
            set { categoryName = value; }
        }
        private string manufactureName;

        public string ManufactureName
        {
            get { return getManufactureName(); }
            set { manufactureName = value; }
        }

        private string getManufactureName() {
            SqlConnection conn = MyConnect.getConnection();
            conn.Open();
            string name = "";
            try
            {
                string sql = "SELECT name FROM manufacture WHERE id ='"+manufactureID+"'";
                SqlCommand cmd = new SqlCommand(sql, conn);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read()) {
                    name = dr.GetString(0);
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                conn.Close();
            }
            return name;
        }

        private string getCategoryName()
        {
            SqlConnection conn = MyConnect.getConnection();
            conn.Open();
            string name = "";
            try
            {
                string sql = "SELECT name FROM category WHERE id ='" + categoryID + "'";
                SqlCommand cmd = new SqlCommand(sql, conn);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    name = dr.GetString(0);
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                conn.Close();
            }
            return name;
        }

        public Product() { 
        }

        public Product(String name, string price, String manu,
            String cate, String detail, String intro, String info, String img, DateTime createdDate)
        {
            this.name = name;
            this.price = price;
            this.manufactureID = manu;
            this.categoryID = cate;
            this.detail = detail;
            this.introduce = info;
            this.information = info;
            this.image = img;
            this.createdDate = createdDate;
        }

        private int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        private String name;

        public String Name
        {
            get { return name; }
            set { name = value; }
        }
        private string price;

        public string Price
        {
            get { return price; }
            set { price = value; }
        }
        private String manufactureID;

        public String ManufactureID
        {
            get { return manufactureID; }
            set { manufactureID = value; }
        }
        private String categoryID;

        public String CategoryID
        {
            get { return categoryID; }
            set { categoryID = value; }
        }
        private String detail;

        public String Detail
        {
            get { return detail; }
            set { detail = value; }
        }
        private String introduce;

        public String Introduce
        {
            get { return introduce; }
            set { introduce = value; }
        }
        private String information;

        public String Information
        {
            get { return information; }
            set { information = value; }
        }
        private String image;

        public String Image
        {
            get { return image; }
            set { image = value; }
        }
        private DateTime createdDate;

        public DateTime CreatedDate
        {
            get { return createdDate; }
            set { createdDate = value; }
        }
	}
}
